package com.pubg.information.serviceImpl;

import com.alibaba.fastjson.JSONObject;
import com.pubg.information.bean.Comment;
import com.pubg.information.mapper.CommentMapper;
import com.pubg.information.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired(required=false)
    CommentMapper commentMapper;

    @Override
    public Comment insComment(JSONObject json) {
        Comment comment = new Comment();
        String name = json.getString("name");
        if (name == null || "".equals(name)){
            comment.setName("游客");
        }else{
            comment.setName(name);
        }
        comment.setContent(json.getString("content"));
        comment.setRotationid(json.getString("rotationid"));
        Date dNow = new Date( );
        SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
        comment.setCotime(ft.format(dNow));
        commentMapper.insComment(comment);
        return comment;
    }
}
